<?php
import("com.yamvc.event.EventDispatcher");
import("com.yamvc.event.Event");
import("com.yamvc.event.EventListener");
class Mediator {
	/**
	 * Enter description here...
	 *
	 * @var ITemplate
	 */
	protected $_template;
	protected $_currentState;
	protected $_name;
	private $_params=array();
	public function __construct(ITemplate $template,$name=null){
		$this->_template = $template;
		$this->_name=$name;
		$this->addEventListener(ApplicationEvent::PRERENDER,new EventListener($this,"initState"));
	}
	
	public function setParam($name,$value){
		$this->_params[$name] = $value;
	}
	public function getParam($name){
		if (!isset($this->_params[$name])) {
			throw new NullPointerException();
		}
		return $this->_params[$name];
	}
	
	public function changeState($state){
		$this->_currentState=$state;
	}
	
	public function initState(){
		if($this->_currentState!=null){
			$this->_currentState->init();
		}
	}
	
	public function addEventListener($eventType,EventListener $eventListener){
		Controller::instance()->addEventListener($eventType,$eventListener);
	}
	public function dispatchEvent(Event $event){
		Controller::instance()->dispatchEvent($event);
	}
	
	/**
	 * Enter description here...
	 *
	 * @return Config
	 */
	public function getConfig(){
		return Application::getAppInstance()->getConfig();
	}
	/**
	 * Enter description here...
	 *
	 * @param string $name
	 * @return ITemplate
	 */
	public function createTemplate($name){
		return View::instance()->createTemplate($name);
	}
}

?>